package com.insurance.modules.claim.controller;

import com.alibaba.fastjson.JSONObject;
import com.insurance.common.common.ResponseData;
import com.insurance.modules.claim.service.OssFileManagermentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author Daniel
 */
@Slf4j
@RestController
@Api(description = "文件上传和下载接口")
@RequestMapping("/migrantWorkers")
@Transactional
public class FileController {

    @Autowired
    private OssFileManagermentService ossFileManagermentService;

    @RequestMapping(value = "/file/upload",method = RequestMethod.POST)
    @ApiOperation(value = "文件上传接口")
    public ResponseData<String> upload(@RequestBody JSONObject jsonString) throws IOException {
        return ossFileManagermentService.uploadFile(jsonString);
    }

    @RequestMapping(value = "/file/download",method = RequestMethod.POST)
    @ApiOperation(value = "文件下载接口")
    public ResponseData<String> download (@RequestBody JSONObject jsonString) throws IOException {
        return ossFileManagermentService.downloadFile(jsonString);
    }

    @RequestMapping(value = "/file/delete",method = RequestMethod.POST)
    @ApiOperation(value = "文件删除接口")
    public ResponseData<String> delete (@RequestBody JSONObject jsonString) throws IOException {
        return ossFileManagermentService.deleteFile(jsonString);
    }

    @RequestMapping(value = "/file/preview",method = RequestMethod.POST)
    @ApiOperation(value = "文件预览接口")
    public ResponseData<String> preview (@RequestBody JSONObject jsonString) throws IOException {
        return ossFileManagermentService.previewFile(jsonString);
    }


}
